<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cash extends CI_Controller {
	function __construct(){
		parent::__construct();
		$this->load->library('Huashang/user');
		$this->user->checkLogin();
	}
	//载入公司入款列表
	public function index(){
		$data['type']=$this->uri->segment(3);
	    $data['auth']=explode(',', $this->input->get('auth'));
		$this->load->view('cash/deposit/list',$data);
	}

	//线上入款
	public function income()
    {
        $data['type']=$this->uri->segment(3);
        $data['auth']=explode(',', $this->input->get('auth'));
        $this->load->view('cash/income/list',$data);
    }

    //优惠卡入款
    public function coupon()
    {
        $data['type']=$this->uri->segment(3);
        $data['auth']=explode(',', $this->input->get('auth'));

        $this->load->view('cash/coupon/list',$data);
    }

    public function payment()
    {
        $data['type']=$this->uri->segment(3);
        $data['auth']=explode(',', $this->input->get('auth'));
        $this->load->view('cash/payment/list',$data);
    }

    public function payment_cancel()
    {
        $this->load->view('cash/payment/payment_cancel');
    }

    public function ring_setting()
    {
        $this->load->view('cash/payment/ring_setting');
    }

	//获取会员列表
	public function getlist(){
		$arr=array('total'=>4,'rows'=>array(
			array('id'=>1,'user'=>'user001','coupon_sn'=>'29290109292','charge_pwd'=>'hz180',
			'charge_money'=>99992, 'charge_date'=>'2017-02-18 13:00:00', 'charge_ip'=>'127.0.0.1'),
            array('id'=>2,'user'=>'user001','coupon_sn'=>'29290109292','charge_pwd'=>'hz180',
                'charge_money'=>99992, 'charge_date'=>'2017-02-18 13:00:00', 'charge_ip'=>'127.0.0.1'),
            array('id'=>3,'user'=>'user001','coupon_sn'=>'29290109292','charge_pwd'=>'hz180',
                'charge_money'=>99992, 'charge_date'=>'2017-02-18 13:00:00', 'charge_ip'=>'127.0.0.1'),
            array('id'=>4,'user'=>'user001','coupon_sn'=>'29290109292','charge_pwd'=>'hz180',
                'charge_money'=>99992, 'charge_date'=>'2017-02-18 13:00:00', 'charge_ip'=>'127.0.0.1'),
		));

	    echo json_encode($arr);
	}
	
	//公司入款
    public function get_deposit_list()
    {
        $arr =
            array(
                'total'=>4,
                'rows'=>array(
                    array(
                        'id'=>1,'order_no'=>'22335555', 'level'=>'未分层','agent'=>'tex_default_dl','username'=>'username','is_first'=>'是',
                        'deposit_person'=>'刘飞','deposit_time'=>'2017-02-20 17:06:20', 'deposit'=>10000.00,'in_money'=>999,'discount'=>100,
                        'deposit_type'=>'網銀轉帳', 'in_money'=>'10150.00','remark'=>'', 'bank_card_person'=>'怡宝','bank_card_no'=>'622588127584877',
                        'status'=>1, 'is_first'=>'1', 'operator'=>'哈哈哈', 'operate_time'=>'2017-3-18 12:32:32','bank_name'=>'中国银行'
                    ),
                    array(
                        'id'=>2,'order_no'=>'22335555', 'level'=>'未分层','agent'=>'tex_default_dl','username'=>'username','is_first'=>'是',
                        'deposit_person'=>'刘飞','deposit_time'=>'2017-02-20 17:06:20', 'deposit'=>10000.00,'in_money'=>999,'discount'=>100,
                        'deposit_type'=>'網銀轉帳', 'in_money'=>'10150.00','remark'=>'', 'bank_card_person'=>'怡宝','bank_card_no'=>'622588127584877',
                        'status'=>2, 'is_first'=>'1', 'operator'=>'哈哈哈', 'operate_time'=>'2017-3-18 12:32:32','bank_name'=>'中国银行',
                    ),
                    array(
                        'id'=>3,'order_no'=>'22335555', 'level'=>'未分层','agent'=>'tex_default_dl','username'=>'username','is_first'=>'是',
                        'deposit_person'=>'刘飞','deposit_time'=>'2017-02-20 17:06:20', 'deposit'=>10000.00,'in_money'=>999,'discount'=>100,
                        'deposit_type'=>'網銀轉帳', 'in_money'=>'10150.00','remark'=>'', 'bank_card_person'=>'怡宝','bank_card_no'=>'622588127584877',
                        'status'=>3, 'is_first'=>'1', 'operator'=>'哈哈哈', 'operate_time'=>'2017-3-18 12:32:32','bank_name'=>'中国银行',
                    ),
                    array(
                        'id'=>4,'order_no'=>'22335555', 'level'=>'未分层','agent'=>'tex_default_dl','username'=>'username','is_first'=>'是',
                        'deposit_person'=>'刘飞','deposit_time'=>'2017-02-20 17:06:20', 'deposit'=>10000.00,'in_money'=>999,'discount'=>100,
                        'deposit_type'=>'網銀轉帳', 'in_money'=>'10150.00','remark'=>'', 'bank_card_person'=>'怡宝','bank_card_no'=>'622588127584877',
                        'status'=>4, 'is_first'=>'1', 'operator'=>'哈哈哈', 'operate_time'=>'2017-3-18 12:32:32','bank_name'=>'中国银行',
                    ),
                ),
                'footer' => array(
                    array('order_no'=>'<div style="word-wrap: break-word; white-space: pre-wrap;">小计: 笔数：3</div>','level_agent'=>'<div style="word-wrap: break-word;">存入金額：20000</div>','username'=>'<div style="word-wrap: break-word; white-space: pre-wrap;">存款優惠：200</div>','deposit_info'=>'<div style="word-wrap: break-word; white-space: pre-wrap;">其他優惠：100</div>','have_in'=>'<div style="word-wrap: break-word; white-space: pre-wrap;">存入總金額：20300</div>'),
                ),
            );

        echo json_encode($arr);
    }

    public function coupon_edit()
    {
        $data['type']=$this->uri->segment(3);
        $data['auth']=explode(',', $this->input->get('auth'));
        $this->load->view('cash/coupon/edit',$data);
	}

	//现金系统-存取款
    public function deposit_withdraw_money()
    {
        $data = array();
        $this->load->view('cash/deposit_withdraw_money', $data);
	}

    public function get_payment_list()
    {
        $arr =
            array(
                'total'=>4,
                'rows'=>array(
                    array(
                        'site_name'=>'www.kgbet.cc', 'user_level'=>'未分层','agent'=>'agent','username'=>'username','is_first'=>'是',
                        'limit_money'=>6000, 'charge_fee'=>0, 'coupon_money'=>100, 'manage_fee'=>2000,'pay_fee'=>3000,'money'=>3000,
                        'coupon'=>300,'payment_date'=>'2016-10-22 10:33:33','audit'=>'--','status'=>'1','op'=>'1admin'
                    ),
                    array(
                        'site_name'=>'www.kgbet.cc', 'user_level'=>'未分层','agent'=>'agent','username'=>'username','is_first'=>'是',
                        'limit_money'=>6000, 'charge_fee'=>0, 'coupon_money'=>100, 'manage_fee'=>2000,'pay_fee'=>3000,'money'=>3000,
                        'coupon'=>300,'payment_date'=>'2016-10-22 10:33:33','audit'=>'--','status'=>'2','op'=>'1admin'
                    ),
                    array(
                        'site_name'=>'www.kgbet.cc', 'user_level'=>'未分层','agent'=>'agent','username'=>'username','is_first'=>'是',
                        'limit_money'=>6000, 'charge_fee'=>0, 'coupon_money'=>100, 'manage_fee'=>2000,'pay_fee'=>3000,'money'=>3000,
                        'coupon'=>300,'payment_date'=>'2016-10-22 10:33:33','audit'=>'--','status'=>'3','op'=>'1admin'
                    ),
                    array(
                        'site_name'=>'www.kgbet.cc', 'user_level'=>'未分层','agent'=>'agent','username'=>'username','is_first'=>'是',
                        'limit_money'=>6000, 'charge_fee'=>0, 'coupon_money'=>100, 'manage_fee'=>2000,'pay_fee'=>3000,'money'=>3000,
                        'coupon'=>300,'payment_date'=>'2016-10-22 10:33:33','audit'=>'--','status'=>'3','op'=>'1admin'
                    ),
                    array(
                        'site_name'=>'www.kgbet.cc', 'user_level'=>'未分层','agent'=>'agent','username'=>'username','is_first'=>'是',
                        'limit_money'=>6000, 'charge_fee'=>0, 'coupon_money'=>100, 'manage_fee'=>2000,'pay_fee'=>3000,'money'=>3000,
                        'coupon'=>300,'payment_date'=>'2016-10-22 10:33:33','audit'=>'--','status'=>'4','op'=>'1admin'
                    ),
                    array(
                        'site_name'=>'www.kgbet.cc', 'user_level'=>'未分层','agent'=>'agent','username'=>'username','is_first'=>'是',
                        'limit_money'=>6000, 'charge_fee'=>0, 'coupon_money'=>100, 'manage_fee'=>2000,'pay_fee'=>3000,'money'=>3000,
                        'coupon'=>300,'payment_date'=>'2016-10-22 10:33:33','audit'=>'--','status'=>'5','op'=>'1admin'
                    )
                )
        );

        echo json_encode($arr);
	}

	//出入汇总
    public function amount_summary()
    {
        $data = array();
        $this->load->view('cash/amount_summary', $data);
	}

    public function get_amount_summary_list()
    {
        echo json_encode(
            array(
                'total' =>  9,
                'rows'  =>  array(
                    array('in'=>'公司入款', 'in_money'=>'0(0筆)(0人)	', 'out'=>'会员出款','out_detail'=>'0(0筆)(0人)'),
                    array('in'=>'公司入款', 'in_money'=>'0(0筆)(0人)	', 'out'=>'会员出款','out_detail'=>'0(0筆)(0人)'),
                    array('in'=>'公司入款', 'in_money'=>'0(0筆)(0人)	', 'out'=>'会员出款','out_detail'=>'0(0筆)(0人)'),
                    array('id'=>1, 'in'=>'公司入款', 'in_money'=>'0(0筆)(0人)	', 'out'=>'会员出款','out_detail'=>'0(0筆)(0人)'),
                ),
                'footer' => array(
                    array('in' => '實際盈虧：0         賬目統計：0'),
                ),
            ), JSON_UNESCAPED_UNICODE);
    }

    //现金流水
    public function cash_system()
    {
        $data = array();

        $this->load->view('cash/cash_system', $data);
    }

    public function get_cash_list()
    {
        echo json_encode(
            array(
                'total' =>  4,
                'rows'  =>  array(
                    array('username'=>'账号名称', 'money_type'=>'人民币', 'type'=>'类别', 'cash_type'=>'交易类别', 'cash_money'=>288193, 'money'=>315772, 'cash_date'=>'2017-2-18 16:30:20', 'remark'=>'备注999'),
                    array('username'=>'账号名称', 'money_type'=>'人民币', 'type'=>'类别', 'cash_type'=>'交易类别', 'cash_money'=>288193, 'money'=>315772, 'cash_date'=>'2017-2-18 16:30:20', 'remark'=>'备注999'),
                    array('username'=>'账号名称', 'money_type'=>'人民币', 'type'=>'类别', 'cash_type'=>'交易类别', 'cash_money'=>288193, 'money'=>315772, 'cash_date'=>'2017-2-18 16:30:20', 'remark'=>'备注999'),
                    array('username'=>'账号名称', 'money_type'=>'人民币', 'type'=>'类别', 'cash_type'=>'交易类别', 'cash_money'=>288193, 'money'=>315772, 'cash_date'=>'2017-2-18 16:30:20', 'remark'=>'备注999'),
                ),
            ), JSON_UNESCAPED_UNICODE);
    }

    public function get_audit_log()
    {
        echo json_encode(
            array(
                'total' =>  3,
                'rows'  =>  array(
                    array('username'=>'账号名称', 'content'=>'人民币', 'date'=>'2017-2-18 16:30:30'),
                    array('username'=>'账号名称', 'content'=>'人民币', 'date'=>'2017-2-18 16:30:30'),
                    array('username'=>'账号名称', 'content'=>'人民币', 'date'=>'2017-2-18 16:30:30'),
                ),
            ), JSON_UNESCAPED_UNICODE);
    }

    public function audit_list()
    {
        $data['type']=$this->uri->segment(3);
        $data['auth']=explode(',', $this->input->get('auth'));

        $this->load->view('cash/audit/list', $data);
    }

    public function get_audit_list()
    {
        
    }

    public function balance()
    {
        $data = array();

        $this->load->view('cash/balance', $data);
    }

    public function get_balance_list()
    {
        echo <<<content
{
    "total": 1, 
    "rows": [
        {
            "balance": "系統額度",
            "enable": "13286991131940",
            "stop": "0",
            "update_time": "2017-03-15 04:16:09"
        }
    ]
}
content;
    }
    
    //稽查日志
    public function audit_log()
    {
        $data = array();

        $this->load->view('cash/audit/audit_log', $data);
    }
    
	//获取线上入款
	public function get_income_list()
    {
        $arr=array('total'=>1,
            'rows'=>array(
                array('id'=>1, 'level'=>'未分层','order_no'=>'333356666','agent'=>'hz180',
                    'username'=>'skkqolalaa',
                    'type'=>'存入总额：10150.00<br>备注：',
                    'income'=>9999,
                    'discount'=>88888,
                    'income_total'=>33333,
                    'pay_type'=>'聚源',
                    'pay_type_id'=>'333333',
                    'operator'=>'kkolla',
                    'create_time'=>'2017-3-18 00:00:00',
                    'operate_time'=>'2017-3-18 00:00:00',
                    ),
        ));

        echo json_encode($arr);
    }

	//保存会员列表
	public function save(){
		$id 		   			= $this -> input -> post('id');
		$row['gg_sort_order'] 	= $this -> input -> post('gg_sort_order');
		if($this -> user -> save($id,$row) && $this -> admin_sh -> add($sh)){
			echo '{"status":"OK","msg":"执行成功"}';
		}else{
			echo '{"status":"ERROR","msg":"执行失败"}';
		}
	}

	public function export(){
		$title='订单报表';
		$fields=array(
				'xz'     =>'订单号',
				'kithe'    =>'层级/代理商',
				'upline'  =>'会员帐号',
				'order_sn'   =>'存款人与时间',
				'username'       =>'存入金额与优惠',
				'type'       =>'存入总额与备注',
				'content' =>'存入银行帐户',
				'money'        =>'状态',
				'rebate'        =>'首存',
				'lucky_price'     =>'操纵者',
				'result'     =>'时间',
		);
		$data=array(
			array('xz'=>'201702200506245398','kithe'=>'未分层<br>tex_default_dl','upline'=>'hz180',
			'order_sn'=>'存款人:刘飞<br>時間:2017-02-20 17:06:20',
			'username'=>'存入金額：10000.00<br>存款/其他優惠：100.00/50.00<br>银行：中国银行<br>方式：網銀轉帳',
			'type'=>'存入总额：10150.00<br>备注：',
			'content'=>'卡主：怡宝【6225881275848776】<br>銀行：中国银行',
			'money'=>'已确认','rebate'=>'是','lucky_price'=>'admin','result'=>'2017-02-20 00:41:04'),
			array('xz'=>'201702200506245398','kithe'=>'未分层<br>tex_default_dl','upline'=>'hz180',
			'order_sn'=>'存款人:刘飞<br>時間:2017-02-20 17:06:20',
			'username'=>'存入金額：10000.00<br>存款/其他優惠：100.00/50.00<br>银行：中国银行<br>方式：網銀轉帳',
			'type'=>'存入总额：10150.00<br>备注：',
			'content'=>'卡主：怡宝【6225881275848776】<br>銀行：中国银行',
			'money'=>'已确认','rebate'=>'是','lucky_price'=>'admin','result'=>'2017-02-20 00:41:04'),
			array('xz'=>'201702200506245398','kithe'=>'未分层<br>tex_default_dl','upline'=>'hz180',
			'order_sn'=>'存款人:刘飞<br>時間:2017-02-20 17:06:20',
			'username'=>'存入金額：10000.00<br>存款/其他優惠：100.00/50.00<br>银行：中国银行<br>方式：網銀轉帳',
			'type'=>'存入总额：10150.00<br>备注：',
			'content'=>'卡主：怡宝【6225881275848776】<br>銀行：中国银行',
			'money'=>'已确认','rebate'=>'是','lucky_price'=>'admin','result'=>'2017-02-20 00:41:04'),
		);
		$this->user->export('公司入款报表',array(array('name'=>'公司入款报表','data'=>$data,'fields'=>$fields)));
	}
	
}